aboutsummaryrefslogtreecommitdiff
path: root/src/routes/projects/[id]
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-10-18 22:22:55 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-10-18 22:22:55 +0200
commit4efed80a2f8dc238b420eadf97d56c3eccaadb76 (patch)
tree7732a80745622c097a9e75dfb056603bceb10a23 /src/routes/projects/[id]
parent0685e9ece66fbcb09c9457027cf7bb2107cc0171 (diff)
refactor: inject the database into every servicemain
Groceries, projects, references and routines become classes holding the Drizzle handle, wired once in services/index.ts alongside categories. Tests build their own instance on an in-memory database. Drops the unused projects.loadAll and projects.rename.
Diffstat (limited to 'src/routes/projects/[id]')
-rw-r--r--src/routes/projects/[id]/+page.server.ts23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/routes/projects/[id]/+page.server.ts b/src/routes/projects/[id]/+page.server.ts
index 83d7571..1df28c2 100644
--- a/src/routes/projects/[id]/+page.server.ts
+++ b/src/routes/projects/[id]/+page.server.ts
@@ -1,13 +1,5 @@
import { error, fail, redirect } from '@sveltejs/kit';
-import {
- archive as archiveProject,
- getById,
-} from '$lib/server/services/projects';
-import {
- add,
- loadProjectDashboard,
- loadArchived,
-} from '$lib/server/services/routines';
+import { projectsService, routinesService } from '$lib/server/services';
import { completeRoutineAction } from '$lib/server/services/routine-actions';
import { numericId, parseFormString } from '$lib/server/services/validation';
import { Frequency } from '$lib/shared/frequency';
@@ -15,12 +7,15 @@ import type { Actions, PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ params }) => {
const id = numericId(params.id);
- const project = await getById(id);
+ const project = await projectsService.getById(id);
if (!project || project.archived) {
throw error(404, 'Projet introuvable');
}
- const dashboard = await loadProjectDashboard(id, Temporal.Now.instant());
- const archived = await loadArchived(id);
+ const dashboard = await routinesService.loadProjectDashboard(
+ id,
+ Temporal.Now.instant(),
+ );
+ const archived = await routinesService.loadArchived(id);
return {
project: { id: project.id, name: project.name },
routines: dashboard.routines,
@@ -38,7 +33,7 @@ export const actions: Actions = {
return fail(400, { error: 'Le nom est requis' });
}
try {
- await add(
+ await routinesService.add(
numericId(params.id),
name,
Frequency.parse(data.get('frequency')?.toString() ?? '').toSpec(),
@@ -55,7 +50,7 @@ export const actions: Actions = {
},
archiveProject: async ({ params }) => {
- await archiveProject(numericId(params.id));
+ await projectsService.archive(numericId(params.id));
throw redirect(303, '/');
},
};